package sy.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.BaseEntity;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.service.CodeServiceI;
import sy.util.StringUtil;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2016-07-07.
 */
@Controller
@RequestMapping("codeController")
public class CodeController extends BaseController {
    @Autowired
    private CodeServiceI codeService;

    @Autowired
    private HttpSession session;
    @RequestMapping("/datagrid.action")
    @ResponseBody
    public DataGrid findPartnerAction(BaseEntity entity){
        return codeService.detagrid(entity);
    }

    /**
     * 添加单位所属栏目
     * @param entity
     * @return
     */
    @RequestMapping("/add_currency.action")
    @ResponseBody
    public Json addInfoAction(BaseEntity entity){
        int rows=0;
        try {
            rows=codeService.addCodeService(entity);
            if (rows>0) logUserAction(session,"codeController/add_code.action",entity.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"添加");
        return js;
    }

    /**
     * 修改单位所属栏目
     * @param entity
     * @return
     */
    @RequestMapping("/edit_currency.action")
    @ResponseBody
    public Json editcodeAction(BaseEntity entity){
        int rows=0;
        try {
            rows=codeService.editCodeService(entity);
            if (rows>0) logUserAction(session,"codeController/edit_code.action",entity.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"修改");
        return js;
    }

    /**
     * 删除单位所属栏目
     * @param entity
     * @return
     */
    @RequestMapping("/del_currency.action")
    @ResponseBody
    public Json delCodeAction(BaseEntity entity){
        int rows=0;
        try {
            rows= codeService.deleteCodeService(entity);
            if (rows>0)   logUserAction(session,"codeController/edit_code.action",entity.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"删除");
        return js;
    }

    @RequestMapping("/find_code.action")
    @ResponseBody
    public List<BaseEntity> findListAction(){
        return codeService.findList("");
    }
}
